package com.yuexunit.operationman.nbsy.module.AfterOperation.ui;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.AfterOperation.AfterOperationContracts;
import com.yuexunit.operationman.nbsy.module.AfterOperation.bean.AfterOperationBean;
import com.yuexunit.operationman.nbsy.module.AfterOperation.model.impl.AfterOperationDetailModel;
import com.yuexunit.operationman.nbsy.module.AfterOperation.presenter.IAfterOperationDetailPresenter;
import com.yuexunit.operationman.nbsy.module.AfterOperation.presenter.impl.AfterOperationDetailPresenter;
import com.yuexunit.operationman.nbsy.module.AfterOperation.ui.view.IAfterOperationDetailView;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by work-jx on 2017/2/28.
 */
public class Act_AfterOperationMain extends BaseKJActivity implements IAfterOperationDetailView{

    @Bind(R.id.titlebar_tv_title)
    TextView titlebarTvTitle;
    @Bind(R.id.afteroperationmain_pic)
    ImageView afteroperationmainPic;
    @Bind(R.id.afteroperationmain_name)
    TextView afteroperationmainName;
    @Bind(R.id.afteroperationmain_age)
    TextView afteroperationmainAge;
    @Bind(R.id.afteroperationmain_sex)
    TextView afteroperationmainSex;
    @Bind(R.id.afteroperationmain_date)
    TextView afteroperationmainDate;
    @Bind(R.id.afteroperationmain_doc)
    TextView afteroperationmainDoc;
    @Bind(R.id.afteroperationmain_bed)
    TextView afteroperationmainBed;

    IAfterOperationDetailPresenter presenter;

    LoadingDialog loadingDialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_afteroperationmain);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        setTitle();
        loadingDialog = new LoadingDialog(this);
        presenter = new AfterOperationDetailPresenter(this,new AfterOperationDetailModel());
    }

    @Override
    public void onResume(){
        super.onResume();
        Map<String, String> params = new HashMap<>();
        params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID)+"");
        presenter.getAfterOperationDate(params);
    }

    private void setTitle()
    {
        titlebarTvTitle.setText("术后随访单");
    }

    @OnClick({R.id.titlebar_img_back, R.id.afteroperationmain_ll_01, R.id.afteroperationmain_ll_02, R.id.afteroperationmain_ll_03, R.id.afteroperationmain_ll_04})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titlebar_img_back:
                finish();
                break;
            case R.id.afteroperationmain_ll_01:
                startActivity(new Intent(aty,Act_AfterOperation_ObserveList.class));
                break;
            case R.id.afteroperationmain_ll_02:
                startActivity(new Intent(aty,Act_AfterOperation_AnalgesiaObserveList.class));
                break;
            case R.id.afteroperationmain_ll_03:
                startActivity(new Intent(aty,Act_AfterOperation_Sign.class));
                break;
            case R.id.afteroperationmain_ll_04:
                startActivity(new Intent(aty,Act_AfterOperation_Preview.class));
                break;
        }
    }

    @Override
    public void getAfterOperationDate(AfterOperationBean afterOperationBean) {
        if(afterOperationBean.getCode() == 200)
        {
            AppConfig.AFTEROPERATIONBEAN =afterOperationBean;
            afteroperationmainName.setText(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisit().getPatientName());
            afteroperationmainAge.setText(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisit().getPatientAge());
            if(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisit().getPatientSex().equals("1")) {
                afteroperationmainSex.setText("男");
            }else if(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisit().getPatientSex().equals("2"))
            {
                afteroperationmainSex.setText("女");
            }
            else {
                afteroperationmainSex.setText("不详");
            }
            afteroperationmainDoc.setText(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisit().getPatientBed());
            afteroperationmainBed.setText(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisit().getInHospitalNo());
            if(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitObList() == null)
            {
                AppConfig.AFTEROPERATIONBEAN.getObject().setAoVisitObList(AfterOperationContracts.aoVisitObListEntities(this));
            }
            if(AppConfig.AFTEROPERATIONBEAN.getObject().getAoVisitPainList() == null)
            {
                AppConfig.AFTEROPERATIONBEAN.getObject().setAoVisitPainList(AfterOperationContracts.aoVisitPainListEntities(this));
            }
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }
}


